package com.yonyou.crm.cum.customer.queryplan;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.yonyou.crm.common.biz.service.BaseBizServiceImpl;
import com.yonyou.crm.common.login.context.LoginContextConstant;
import com.yonyou.crm.cum.customer.entity.GroupCustomerDO;
import com.yonyou.iuap.context.InvocationInfoProxy;

@Service
public class GroupCustomerQueryPlanHandle extends BaseBizServiceImpl<GroupCustomerDO>{
	
	public List<String> handle(Map<String, Object> param){

		List<String> idList = new ArrayList<String>();
		Object searchPlanObj = param.get("id");
		if (searchPlanObj != null) {
			
			int searchPlan = Integer.parseInt(searchPlanObj.toString());
			//避免和列表条件冲突
			param.put("id", null);
			
			param.put("userId", InvocationInfoProxy.getParameter(LoginContextConstant.UserId));

			if (searchPlan == 1) {//全部
				param.put("orderBy", "c.name asc");
			}
			else if (searchPlan == 2) {// 我关注
				idList = getIdList("selectListByFollow", param);
				
			} else if (searchPlan == 3) {//最近查看
				idList = getIdList("selectListByView", param);
				
			}
			else if (searchPlan == 4) {//最近创建
				param.put("orderBy", "c.created_time desc");
			}

			//集团客户分配
			if (searchPlan == 27) {//全部
				param.put("orderBy", "c.name asc");
			}
			else if (searchPlan == 28) {//未分配
				idList = getIdList("selectListByView", param);
				
			}else if (searchPlan == 29) {//已分配
				idList = getIdList("selectListByAssign", param);
				
			}else if (searchPlan == 30) {//最近查看
				idList = getIdList("selectListByNoAssign", param);
				
			}else if (searchPlan == 31) {//最近创建
				param.put("orderBy", "c.created_time desc");
				
			}
			
			param.put("userId", null);
		}
		
		return idList;
	}
	
	
	private List<String> getIdList(String funcName, Map<String, Object> param) {
		List<String> idList = dao.selectStrList(GroupCustomerDO.class, funcName, param);
		//拼接无数据条件
		if (idList == null || idList.size() == 0) {
			idList.add("0");
		}
		return idList;
	}
}
